package com.api.ittools.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

@Data
@TableName("tool_ds")
public class ToolDatasource {
    @TableId(type = IdType.AUTO)
    private Long dsId ;
    private String dsName ;
    private String username ;
    private String password ;

    private String driverClass ;

    private String dsUrl ;

    private Long owner = 1L;

    private LocalDateTime createTime ;

    public ToolDatasource(String username , String password , String url , String driverClass){
        this.username = username ;
        this.password = password ;
        this.dsUrl = url ;
        this.driverClass = driverClass ;
    }

    public String getDataBaseName(){
        return dsName ;
    }

    public ToolDatasource(){}

    public String getDbType(){
        if(driverClass.startsWith("jdbc:mysql")){
            return "mysql" ;
        }else if(driverClass.startsWith("jdbc:oracle")){
            return "oracle" ;
        }
        return "" ;
    }
}
